package m1.server.config.connector;

import m1.server.config.connector.glue.SQLQueryGlue;
import m1.server.config.connector.role.CalleeDBQuery;
import m1.server.config.connector.role.CalleeQueryReceive;
import m1.server.config.connector.role.CallerDBQuery;
import m1.server.config.connector.role.CallerQuery;
import m2.connector.Connector;

public class SQLQuery extends Connector{

	private static SQLQuery sqlQuery = null;
	
	private SQLQuery(){
		addGlueIn(new SQLQueryGlue());
		addGlueOut(new SQLQueryGlue());
		
		CallerDBQuery callerDBQuery = new CallerDBQuery();
		CallerQuery callerQuery = new CallerQuery();
		CalleeDBQuery calleeDBQuery = new CalleeDBQuery();
		CalleeQueryReceive calleeQueryReceive = new CalleeQueryReceive();
		
		addProvidedRole(calleeDBQuery, calleeQueryReceive);
		addRequiredRole(callerDBQuery, callerQuery);		
		
		((SQLQueryGlue)getGlueIn()).sQLQueryConnectRequiredRoleToProvidedRole(callerQuery, calleeDBQuery);
		((SQLQueryGlue)getGlueOut()).sQLQueryConnectRequiredRoleToProvidedRole(callerDBQuery, calleeQueryReceive);
		
	}
	
	/**
	 * 
	 * @return
	 */
	public static SQLQuery getInstance(){
		if (sqlQuery == null){
			sqlQuery = new SQLQuery();
		}
		return sqlQuery;
	}
	
}
